<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>从小到大排序</title>
    <script>
        function sort(array){
            
            var t = 0;
            var min = 0
            for(var i = 0;i<array.length-1;i++){
                var n = i;
                for(var j = i;j<array.length - 1;j++){
                    min = array[n];
                    if(min > array[j]){
                        n=j;
                    }
                }
                if(n!=i){
                    t = array[i];
                    array[i] = array[n];
                    array[n] = t;
                }
            }
            return array;
        }
        var array = [4,2,3,1,5];
        console.log(sort(array));
    </script>
</head>
<body>
    
</body>
</html>